﻿<html>
<head>
<meta charset="UTF-8">
<title>文件上传表单</title>
</head>
<!-- <script src='ListDirfile.js' type="text/javascript"></script> -->
 <script>
                    <!-- exports.initialize2 = function(req, res){ -->
   <!-- console.log('initializing2');  -->
   <!-- res.send("来自服务器的响应"); } -->
 </script>
<body>
<h3>文件上传：</h3>
选择一个文件上传: <br />
<form action="/file_upload" method="post" enctype="multipart/form-data">
<input type="file" name="image" size="50" />
<br />
<input type="submit" value="上传文件" />
</form>
<input type = "button"  value="服务文件清单" onclick="location.href='/FileList.html'">
<button type="button" onclick="loadXMLDoc()">请求数据</button>
 <script>
                        //AJAX
                        function loadXMLDoc()
                        {
                            var xmlhttp;
                            var str;
                            if (window.XMLHttpRequest)
                            {// code for IE7+, Firefox, Chrome, Opera, Safari
                                xmlhttp=new XMLHttpRequest();
                            }
                            else
                            {// code for IE6, IE5
                                xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
                            }
                            xmlhttp.onreadystatechange=function()
                            {
                                if (xmlhttp.readyState==4 && xmlhttp.status==200)
                                {
                                    str = xmlhttp.responseText;//得到服务器响应
									alert(str);
									//json处理方式
									var obj = JSON.parse(str);
									alert(obj.BlockList.length);
									for(var i = 0; i < obj.BlockList.length; i++) 
									{
										  filePath = obj.BlockList[i];
										  var arr = filePath.split('/');
										  var len = arr.length;
										  return arr[len-1];
									}
                                    //document.getElementById("myDiv").innerHTML=str;
                                }
                            }

                            xmlhttp.open("GET","/FileList.html",true);
                            xmlhttp.send();
	                      }
                    </script>
</body>
</html>